home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Resources / Online / Term / Extras / Source / gtlayout-source.lha / LTP_CorrectItemList.c < prev    next >
C/C++ Source or Header  |  1996-03-18  |  2KB  |  99 lines

  1. /*
  2. **    GadTools layout toolkit
  3. **
  4. **    Copyright © 1993-1996 by Olaf `Olsen' Barthel
  5. **        Freely distributable.
  6. **
  7. **    :ts=4
  8. */
  9.  
  10. #include "gtlayout_global.h"
  11.  
  12. #ifdef DO_MENUS
  13.  
  14.     /* LTP_CorrectItemList(RootMenu *Root,ItemNode *First,ItemNode *Last):
  15.      *
  16.      *    Chop nasty menus in two if they're too tall for this screen.
  17.      */
  18.  
  19. BOOL
  20. LTP_CorrectItemList(RootMenu *Root,ItemNode *First,ItemNode *Last)
  21. {
  22.     ItemNode    *Item;
  23.     ULONG         Count = 0;
  24.     LONG         Mask;
  25.     BOOL         Overshoot = FALSE;
  26.  
  27.     Mask = First->Flags & ITEMF_IsSub;
  28.  
  29.         // Count the number of items in this menu
  30.         // and check if there is one too many in it
  31.  
  32.     for(Item = First ; Item->Node.mln_Succ ; Item = (ItemNode *)Item->Node.mln_Succ)
  33.     {
  34.         if((Item->Flags & ITEMF_IsSub) == Mask)
  35.         {
  36.             Count++;
  37.  
  38.             if(Item->Top + Item->Item.Height + 2 > Root->Screen->Height)
  39.                 Overshoot = TRUE;
  40.         }
  41.  
  42.         if(Item == Last)
  43.             break;
  44.     }
  45.  
  46.         // Did we scrape it?
  47.  
  48.     if(Overshoot && Count > 1)
  49.     {
  50.         ItemNode    *Here;
  51.         ULONG         i = (Count + 1) / 2;
  52.         LONG         Top,Left;
  53.  
  54.             // Find the median or whatever it's called in this part of the world
  55.  
  56.         for(Here = First ; i > 0 && Here->Node.mln_Succ ; Here = (ItemNode *)Here->Node.mln_Succ)
  57.         {
  58.             if((Here->Flags & ITEMF_IsSub) == Mask)
  59.                 i--;
  60.         }
  61.  
  62.             // Shrink the two halves of the menu down to
  63.             // their minimum sizes
  64.  
  65.         LTP_ShrinkMenu(Root,First,(ItemNode *)Here->Node.mln_Pred,Mask);
  66.         LTP_ShrinkMenu(Root,Here,Last,Mask);
  67.  
  68.             // Chop off the other half and stick it
  69.             // on at the right
  70.  
  71.         Left    = First->Item.LeftEdge + First->Item.Width + 2;
  72.         Top        = First->Item.TopEdge;
  73.  
  74.             // Move the items over to the right
  75.  
  76.         for(;;)
  77.         {
  78.             if((Here->Flags & ITEMF_IsSub) == Mask)
  79.             {
  80.                 Here->Item.LeftEdge    = Left;
  81.                 Here->Item.TopEdge    = Top;
  82.  
  83.                 Top += Here->Item.Height;
  84.             }
  85.  
  86.             if(Here == Last)
  87.                 break;
  88.             else
  89.                 Here = (ItemNode *)Here->Node.mln_Succ;
  90.         }
  91.  
  92.         return(TRUE);
  93.     }
  94.     else
  95.         return(FALSE);
  96. }
  97.  
  98. #endif    /* DO_MENUS */
  99.